package com.teradata.interceptor.controller;

import com.teradata.interceptor.model.OdataModelParams;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OdataController {
    @GetMapping(name = "/odata")
    //@RequestParam("appId") String appId,@RequestParam("apiName") String apiName, @RequestParam("apiVersion") String apiVersion ,
    public OdataModelParams getParams(@RequestParam(name = "$select", required = false, defaultValue = "*") String select, @RequestParam(name = "$filter", required = false, defaultValue = "") String filter, @RequestParam(name = "$orderby", required = false, defaultValue = "") String orderby, @RequestParam(name = "$top", required = false, defaultValue = "") String top) {
        //System.out.println("appId:" + appId + " want access the " + apiName + ":" + apiVersion);

        OdataModelParams odataModelParams = new OdataModelParams();
        odataModelParams.setSelect(select);
        odataModelParams.setFilter(filter);
        odataModelParams.setOrderby(orderby);
        odataModelParams.setTop(top);
        System.out.println("The params is:[" + odataModelParams + "]");
        System.out.println("The select is:[" + odataModelParams.getSelect() + "]");
        System.out.println("The where is:[" + odataModelParams.getFilter() + "]");
        return odataModelParams;
    }
}
